package com.example.emos.wx.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @ClassName : EmailTask
 * @Author : 骆发茂
 * @Date: 2021/10/21 23:36
 * @Description :
 */

@Component
@Scope("prototype")//pringframework的
@Slf4j
public class EmailTask implements Serializable {


    /*用来发件*/
    @Autowired
    private JavaMailSender javaMailSender;


    /*发件人的邮箱*/
    @Value("${emos.email.system}")
    private String mailbox;

    /*开启异步*/
    /**用来返送邮件的主函数，会在签到的时候被调用*/
    @Async
    public void sendAsync(SimpleMailMessage message){
        //从哪发
        message.setFrom(mailbox);
        //抄送人，发给谁，避免被认为是垃圾邮件
        message.setCc(mailbox);
        javaMailSender.send(message);
    }
}